import request from '@/utils/axios';
import constant from "@/utils/constant";
import appName from "@/api/appName";

/************************************* 节点逻辑管理 *****************************************/
// 节点逻辑分页查询
export function getNodePage(params) {
  return request({
    url: constant.taskApi + '/setting/node/page',
    method: 'post',
    data: params
  });
}

// 节点逻辑所有
export function getNodeAll() {
  return request({
    url: constant.taskApi + '/setting/node/all',
    method: 'post',
    data: {}
  });
}

// 节点逻辑新增
export function doNodeAdd(params) {
  return request({
    url: constant.taskApi + '/setting/node/add',
    method: 'post',
    data: params
  });
}

// 节点逻辑更新
export function doNodeUpdate(params) {
  return request({
    url: constant.taskApi + `/setting/node/update/${params.id}`,
    method: 'post',
    data: params
  });
}

// 节点逻辑根据ID获取一条
export function getOneNode(id) {
  return request({
    url: constant.taskApi + `/setting/node/get/${id}`,
    method: 'post',
    data: {}
  });
}

// 节点逻辑根据ID删除一条
export function doNodeDelete(id) {
  return request({
    url: constant.taskApi + `/setting/node/delete/${id}`,
    method: 'post',
    data: {}
  });
}

/************************************* 节点逻辑流转 *****************************************/
// 节点流转分页查询
export function getNodeChangePage(params) {
  return request({
    url: constant.taskApi + '/setting/nodeChange/page',
    method: 'post',
    data: params
  });
}

// 节点流转操作
export function doNodeChange(params) {
  return request({
    url: constant.taskApi + '/setting/nodeChange/nextNodeEdit',
    method: 'post',
    data: params
  });
}

// 节点流转根据ID获取一条
export function getNodeChange(id) {
  return request({
    url: constant.taskApi + `/setting/nodeChange/get/${id}`,
    method: 'post',
    data: {}
  });
}

/************************************* 核保员等级设置 *****************************************/
// 核保员等级分页查询
export function getUnderwriterPage(params) {
  return request({
    url: constant.taskApi + '/setting/underwriter/page',
    method: 'post',
    data: params
  });
}

// 核保员等级新增
export function doUnderwriterAdd(params) {
  return request({
    url: constant.taskApi + '/setting/underwriter/add',
    method: 'post',
    data: params
  });
}

// 核保员等级更新
export function doUnderwriterUpdate(params) {
  return request({
    url: constant.taskApi + `/setting/underwriter/update/${params.id}`,
    method: 'post',
    data: params
  });
}

// 核保员等级根据ID获取一条
export function getOneUnderwriter(id) {
  return request({
    url: constant.taskApi + `/setting/underwriter/get/${id}`,
    method: 'post',
    data: {}
  });
}

// 核保员等级根据ID删除一条
export function doUnderwriterDelete(id) {
  return request({
    url: constant.taskApi + `/setting/underwriter/delete/${id}`,
    method: 'post',
    data: {}
  });
}

export function validateId(params) {
  return request({
    url: constant.taskApi + '/setting/underwriter/validateOperatorId',
    method: 'post',
    data: params
  });
}
/************************************* 核保自动分配规则 *****************************************/
// 核保自动分配规则信息查询
export function getRuleInfo() {
  return request({
    url: constant.taskApi + '/setting/rule/info',
    method: 'post',
    data: {}
  });
}

// 自动分配规则修改（发布）
export function doRuleUpdate(params) {
  return request({
    url: constant.taskApi + '/setting/rule/update',
    method: 'post',
    data: params
  });
}
// 自动分配获取字典表信息（发布）
export function getBatchOnOrOff(params) {
  return request({
    url: constant.systemApi + '/dict/detail/sdmList',
    method: 'post',
    data: {sdmCode:"batch_auto_distribution",sddCode:"on_or_off"}
  });
}

// 自动分配规则试运行
export function doRuleTest(params) {
  return request({
    url: constant.taskApi + '/nb/task/auto/distribution/test',
    method: 'post',
    data: params
  });
}

/************************************* 工作日设置 *****************************************/
// 工作日设置信息根据年份查询
export function getWorkDayList(year) {
  return request({
    url: constant.systemApi + `/setting/workDay/list?year=${year}`,
    method: 'post',
    data: {}
  });
}

// 工作日设置根据id获取一条
export function getOneWorkDay(time) {
  return request({
    url: constant.systemApi + `/setting/workDay/get?time=${time}`,
    method: 'post',
    data: {}
  });
}

// 工作日设置修改
export function doWorkDayEdit(params) {
  return request({
    url: constant.systemApi + '/setting/workDay/edit',
    method: 'post',
    data: params
  });
}
// 锁定列表
export function getPolicyRList(params) {
  return request({
    url: constant.insureApi + '/proposal/policyRLock/list',
    method: 'post',
    data: params
  });
}
// 锁定列表
export function policyRUnlock(params) {
  return request({
    url: constant.insureApi + '/proposal/policyRLock/unlock',
    method: 'post',
    data: params
  });
}
// 批处理控制列表
export function getBatchConsoleList(params) {
  return request({
    url: constant.taskApi + '/setting/batchCtrl/list',
    method: 'post',
    data: params
  });
}
// 批处理控制编辑
export function batchConsoleEdit(params) {
  return request({
    url: constant.taskApi + '/setting/batchCtrl/updateBySparamid',
    method: 'post',
    data: params
  });
}
// 批处理控制根据key获取详细信息
export function getbatchConsoleById(params) {
  return request({
    url: constant.taskApi + '/setting/batchCtrl/getbatchConsoleById',
    method: 'post',
    data: params
  });
}
//获取当前登录人员的mysql信息并缓存
export function getMysqlInfo(userId){
	let key =userId+"mysqlInfo";
	if (window.sessionStorage.getItem(key)) {
	    let obj = JSON.parse(window.sessionStorage.getItem(key));
	    return new Promise(function (reslove, reject) {
	        reslove(obj)  //状态由等待变为成功，传的参数作为then函数中成功函数的实参
	    });
	} else {
	    return mysqlInfo(userId).then(res => {
	        if (res.resultCode == constant.SUCCESS && res.data) {
	            window.sessionStorage.setItem(key, JSON.stringify(res.data));
	            return new Promise(function (reslove, reject) {
					reslove(res.data) 
				})
			}
		})
	}
}

//获取当前登录人员的机构号并缓存
export function getBranchByUserId(userId){
	let key =userId+"as400organ";
	if (window.sessionStorage.getItem(key)) {
		return new Promise(function (reslove, reject) {
		    reslove(window.sessionStorage.getItem(key))  //状态由等待变为成功，传的参数作为then函数中成功函数的实参
		});
	} else {
		let organ = "";
	    return branchByUserId(userId).then(res => {
	        if (res.resultCode == constant.SUCCESS ) {
	            window.sessionStorage.setItem(key, res.resultMsg);
	            return res.resultMsg;
			}
		})
	}
}
function  mysqlInfo(userId){
	return request({
	  url: constant.taskApi + '/setting/underwriter/mysqlInfo?userId='+userId,
	  method: 'get'
	});
}

function  branchByUserId(userId){
	return request({
	  url: constant.taskApi + '/setting/underwriter/getBranchByUserId?userId='+userId,
	  method: 'get'
	});
}

export function getSysIdInfos(){
    return request({
        url: appName.SCYLOG + '/third/auditlog/getSysIdInfos',
        method: 'get'
    });
}
